package collect.taobao.dao.impl;
import collect.taobao.dao.YaHooDao;
import collect.taobao.bean.YaHooBean;


import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class YaHooDaoImpl extends HibernateDaoSupport implements YaHooDao{
	public int save(YaHooBean yaHooBean) {
		int i=0;
		Session session =null;
		try{
			session = this.getSession();
	        Transaction trans = session.beginTransaction();
			this.getHibernateTemplate().save(yaHooBean);
			trans.commit();   
			i=1;
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			if(session!=null)session.close();
		}
		return i;
	}
	public int delete(YaHooBean yaHooBean) {
		int i=0;
		Session session =null;
		try{
			session = this.getSession();
	        Transaction trans = session.beginTransaction();
			this.getHibernateTemplate().delete(yaHooBean);
			trans.commit();   
			i=1;
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			if(session!=null)session.close();
		}
		return i;
	}

	public int update(YaHooBean yaHooBean) {
		int i=0;
		Session session =null;
		try{
			session = this.getSession();
	        Transaction trans = session.beginTransaction();
			this.getHibernateTemplate().update(yaHooBean);
			trans.commit();   
			i=1;
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			if(session!=null)session.close();
		}
		return i;
	}
	
	public List queryList() {
		return this.getHibernateTemplate().loadAll(YaHooBean.class);
	}

	public YaHooBean query(String id) {
		Session session =null;
		YaHooBean  yaHooBean = null;
		try{
			session = this.getSession();
			yaHooBean = (YaHooBean)session.load(YaHooBean.class, new Integer(id)); 
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			if(session!=null)session.close();
		}
		return yaHooBean;
	}
}
